package com.demoweb.servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.demoweb.model.dao.MemberDao;
import com.demoweb.model.dto.Member;

@WebServlet("/member/view.action")
public class MemberInformServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String idData = req.getParameter("memberid");
		
		
		if(idData == null || idData.length() == 0) {
			resp.sendRedirect("/demoweb/member/list.action");
			return;
		}
		
		MemberDao dao = new MemberDao();
		Member member = dao.getMemberById(idData);
		
		if(member == null) {
			resp.sendRedirect("/demoweb/member/list.action");
			return;
		}
		
	    // Servlet에서 처리된 데이터를 JSP에 전달(requset 객체 이용)
	    req.setAttribute("member", member);
	    
		// 3. 응답 컨텐츠 생성(JSP 이용해서 처리 - jsp page로 forwad)
		RequestDispatcher dispatcher = req
				.getRequestDispatcher("/WEB-INF/views/member/view.jsp");

		dispatcher.forward(req, resp);

	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req,resp);
	}
}
